package com.chenjiajin.controller;

import com.chenjiajin.domain.MybatisDynamic;
import com.chenjiajin.dto.QueryDTO;
import com.chenjiajin.dto.QueryUpdateBatchDTO;
import com.chenjiajin.service.IMybatisDynamicService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class AopController {


    @Autowired
    private IMybatisDynamicService service;

    @RequestMapping("/aop")
    public String aop(String test) {
        System.out.println("这是执行方法");
        return "success";
    }


    @RequestMapping("/aop2")
    public String aop2() {
        // http://localhost/aop2
        System.out.println("这是执行方法2");
        return "success2";
    }

    /*
    {
        "keyword": "6",
        "name": "进",
        "password": "1",
        "message": "4",
        "age": 1,
        "startCreateTime": {{startTime}},
        "endCreateTime": {{endTime}},
        "ids": [ 8,9,10 ]
     }
    */
    @PostMapping("/query")
    public List<MybatisDynamic> query(@RequestBody QueryDTO qo) {

        return service.query(qo);
    }


    /*
          {
              "param": [
                  {
                      "id": 8,
                      "name": "1",
                      "password": "1",
                      "message": "1",
                      "age": "1",
                      "num": "1",
                      "createTime": {{startTime}},
                      "updateTime": {{endTime}}
                  },
                  {
                      "id": 9,
                      "name": "2",
                      "password": "2",
                      "message": "2",
                      "age": "2",
                      "num": "2",
                      "createTime": {{startTime}},
                      "updateTime": {{endTime}}
                  }
              ]
          }
         */
    @PostMapping("/updateDynamic")
    public String updateDynamic(@RequestBody @Validated QueryUpdateBatchDTO qo) {
        service.updateDynamic(qo);
        return "success2";
    }


}